package com.yanqu.road.server.cmd.orewar;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.crossorewar.CrossOreWarRecord;
import com.yanqu.road.entity.enums.activity.eActivityOreWarType;
import com.yanqu.road.entity.orewar.OreWarRecord;
import com.yanqu.road.pb.orewar.OreWarProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.activity.orewar.OreWarActivityMgr;
import com.yanqu.road.server.manger.activity.orewar.OreWarMgr;
import com.yanqu.road.server.pb.OreWarPb;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;

import java.util.ArrayList;
import java.util.List;

//个人的战报
@Cmd(code = Protocol.S_ORE_WAR_RECORD, desc = "矿战战斗记录(被打的记录)")
public class OreWarRecordCmd extends AbstractCommand {

	private int activityId;

	private List<OreWarRecord> recordList = new ArrayList<>();

	private List<CrossOreWarRecord> crossRecordList = new ArrayList<>();

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		OreWarProto.OreGetRecordReqMsg reqMsg = OreWarProto.OreGetRecordReqMsg.parseFrom(packet.getBytes());
		activityId = reqMsg.getActivityId();
		return true;
	}

	@Override
	public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
		ActivityInfo activityInfo = OreWarActivityMgr.getOpenActivityInfo(activityId);
		if(null != activityInfo){
			if(activityInfo.getChildType() == eActivityOreWarType.OreWar.getChildType()){
				recordList = OreWarMgr.getUserOreWarRecord(activityId,player.getUserId());
			}else if(activityInfo.getChildType() == eActivityOreWarType.CrossOreWar.getChildType()){
				crossRecordList = OreWarMgr.getCrossUserOreWarRecord(activityId,player.getUserId());
			}
		}
	}

	@Override
	public void sendData(GamePlayer player) {
		OreWarProto.OreWarRecordListMsg.Builder respMsg = OreWarPb.parseOreWarRecordListMsg(recordList);
		if(crossRecordList.size() > 0){
			respMsg = OreWarPb.parseCrossOreWarRecordListMsg(crossRecordList);
		}
		player.sendPacket(Protocol.U_ORE_WAR_RECORD, respMsg);
	}
}
